﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using InsuranceCompany.Core.Domain.Objects;

namespace InsuranceCompany.Core.Domain.Client
{
    public class Client : Person
    {
        private DateTime createDate;
        public string Adress { get; set; }

        private History History;
        public DateTime CreateDate 
        {
            get
            {
                return createDate;
            } 
            set
            {
                this.resetErrorMessage();
                if(value.CompareTo(DateTime.Today) == 1)
                {
                    this.setErrorMessage("Can't enter future date!");
                    return;
                }
                createDate = value;
            }
        }

        public Client () :base()
        {
            createDate = DateTime.Today;
            Adress = "";
            History = new History();
            History.AddEvent(new Event(DateTime.Today, "Registration"));
        }

        public Client(string name, string surname, int gender, string patronymic = "", string phone = "", string email = "",
                       string adress = "")
            : base(name, surname, gender, patronymic, phone, email)
        {
            createDate = DateTime.Today;
            Adress = adress;
            History = new History();
            History.AddEvent(new Event(DateTime.Today, "Registration"));
        }

        public Client(Client c) :base(c)
        {
            createDate = c.CreateDate;
            Adress = c.Adress;
            History = new History(c.GetHistory());
        }

        public Client(Person p, string adress)
            : base(p.Name, p.Surname, p.Gender, p.Patronymic, p.Phone, p.Email)
        {
            createDate = DateTime.Today;
            Adress = adress;
            History = new History();
            History.AddEvent(new Event(DateTime.Today, "Registration"));
        }
        public History GetHistory() { return this.History; }
        public void AddEvent(Event ev) { this.History.AddEvent(ev); }
    }
}
